home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1998 June
/
Macworld (1998-06).dmg
/
Shareware World
/
Info
/
For Developers
/
MacsBug 6.5.4a4
/
Building dcmds
/
C Samples
/
Drvr.c
next >
Wrap
Text File
|
1998-02-11
|
7KB
|
326 lines
/*
File: Drvr.c
Contains: This is the Unit Table dcmd.
Written by: JM3 = Jim Murphy
DAL = Dave Lyons
sad = Scott Douglass
Copyright: © 1988,1993-1997 by Apple Computer, Inc., All Rights Reserved.
File Ownership:
DRI: Jim Murphy
Other Contact: Dave Lyons
Technology: MacsBug
Writers:
(DAL) Dave Lyons
Change History (most recent first):
<7> 6/17/97 DAL -b = busy only. Version 3.0.1.
<6> 25-Jan-96 JM3 Updated the sample build commands to be current.
<5> 10/27/95 DAL Draw "-nil-" instead of empty-string for nil DRVR handles
(merged in from Scott Douglass' source).
<4> 10-Dec-94 JM3 Updated for new format 3 dcmd requirements.
<3> 3/14/94 DAL Re-layed-out the columns: removed Window and made room for
everything to be nice on 13" monitors. Made the "that's strange"
message not show up for dRef = 0xFFFE (.Sony for HD-20). Now
Hoon is happy.
<2> 9/14/93 DAL made the driver name column wider
Modification history:
7Dec88 sad show driver version
29Nov88 sad revised for new dcmd names
13Oct88 sad written from file.c
The following MPW commands will build the dcmd and copy it to the "Debugger Prefs" file
in the System folder. The dcmd's name in MacsBug will be the name of the file built by
the Linker.
C Drvr.c
Link -o Drvr -sg Main=STDCLIB,STDIO,SANELIB dcmdGlue.a.o Put.c.o Drvr.c.o" ∂
"{Libraries}Runtime.o"
BuildDcmd Drvr 193 -format3
Echo 'include "Drvr";' | Rez -a -o "{SystemFolder}Debugger Prefs"
*/
//#ifdef USESTDIO
// #include <stdio.h>
//#endif
#include <Types.h>
#include <Memory.h>
#include <Devices.h>
#include <SysEqu.h>
#include "dcmd.h"
#include "put.h"
typedef struct DRVR
{
short drvrFlags;
short drvrDelay;
short drvrEMask;
short drvrMenu;
short drvrOpen;
short drvrPrime;
short drvrCtl;
short drvrStatus;
short drvrClose;
Str255 drvrName;
} DRVR;
static void DrawHdr()
{
// 0 1 2 3 4 5 6 7 8 9
// 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
dcmdDrawLine("\pdRef dNum Driver Flg Ver qHead Storage Dely Drvr at DCE at");
}
#define kColumnNameEnd 37
#define kColumnVersionEnd 46
#define kColumnQHeadEnd 54
#define kColumnStorageEnd 64
#define kColumnDriverAtEnd 78
#define kColumnDCEAtEnd 85
static void DrawDCE(int dref, AuxDCE* dcep)
{
DRVR* drvrp;
PutUHexWord(dref);
PutSpace();
PutUHexWord(~dref);
PutSpace();
if (dcep->dCtlFlags & 0x40)
{
if (dcep->dCtlDriver)
{
drvrp = * (DRVR **) dcep->dCtlDriver;
if (drvrp)
PutPStrTruncTo(drvrp->drvrName, kColumnNameEnd);
else
PutPStrTruncTo("\p-purged-", kColumnNameEnd);
}
else
{
PutPStrTruncTo("\p-nil-", kColumnNameEnd);
};
}
else
{
if (dcep->dCtlDriver)
{
drvrp = (DRVR*)dcep->dCtlDriver;
PutPStrTruncTo(drvrp->drvrName, kColumnNameEnd);
}
else
{
PutPStrTruncTo("\p-nil-", kColumnNameEnd);
};
};
PutSpace();
PutChar((dcep->dCtlFlags & 0x80) ? 'B' : 'b');
PutChar((dcep->dCtlFlags & 0x40) ? 'H' : 'P');
PutChar((dcep->dCtlFlags & 0x20) ? 'O' : 'C');
PutSpace();
PutUDecTo((unsigned char) dcep->dCtlQHdr.qFlags,kColumnVersionEnd); // version
PutSpace();
PutUHexZTo((unsigned long) dcep->dCtlQHdr.qHead,8,kColumnQHeadEnd); // qHead
PutSpace();
PutUHexZTo((unsigned long) dcep->dCtlStorage,8,kColumnStorageEnd); // Storage
PutSpace();
PutUHexWord((unsigned long) dcep->dCtlDelay);
PutSpace();
PutUHexZTo((unsigned long) drvrp,8,kColumnDriverAtEnd);
PutSpace();
PutUHexZTo((unsigned long) dcep,8,kColumnDCEAtEnd);
PutLine();
// For drvr FFFE (.Sony for the HD20, pre-SCSI), it's okay that
// the dCtlRefNum is $FFFB (don't whine about it)
if ( (dref != dcep->dCtlRefNum) && ( ((unsigned short) dref) != (unsigned short) 0xFFFE) )
{
PutPStr("\p that is strange: dCtlRefNum = ");
PutUHexWord(dcep->dCtlRefNum);
PutLine();
}
} // DrawDCE
pascal void DoDrvrCommand(dcmdBlock* paramPtr)
{
Boolean doOne = false;
Boolean busyOnly = false;
long dref;
int NumDCEs;
dcmdSwapWorlds();
dcmdDrawLine("\pDisplaying Driver Control Entries");
// Get low-memory values after dcmdSwapWorlds().
NumDCEs = *(unsigned short *)UnitNtryCnt;
if ( dcmdPeekAtNextChar() == '-' )
{
short oldPos = dcmdGetPosition();
short ch;
dcmdGetNextChar(); // eat the "-"
ch = dcmdGetNextChar();
if ( ch == 'b' || ch == 'B' )
busyOnly = true;
else
dcmdSetPosition( oldPos );
}
if ( !busyOnly )
(void) dcmdGetNextExpression(&dref, &doOne);
if (doOne) // info on one specific driver
{
int dnum;
dref = (short) dref;
if (dref < 0)
{
dnum = ~dref;
}
else
{
dnum = dref;
dref = ~dref;
}
if (dnum > NumDCEs)
{
//#ifdef USESTDIO
// Str255 line;
// sprintf(line,"Bad refnum 0x%.4x",(unsigned short)dref);
// dcmdDrawLine((Str255)c2pstr(&line));
//#else
PutPStr("\pBad refnum ");
PutUHexWord(dref);
PutSpace();
PutUHexWord(~dref);
PutLine();
//#endif
}
else
{
AuxDCE** dceh = (*(AuxDCE****)UTableBase)[dnum];
if (dceh)
{
DrawHdr();
DrawDCE(dref,*dceh);
}
else
{
PutPStr("\pDriver ");
PutUHexWord(dref);
PutSpace();
PutUHexWord(~dref);
PutPStr("\p is not in installed");
PutLine();
}
}
}
else // no driver number specified on command line
{
int DCEsUsed = 0;
int dnum;
AuxDCE*** dcehp;
Boolean foundOne = false;
for(dnum = 0, dcehp = *(AuxDCE****)UTableBase; dnum < NumDCEs; dnum++, dcehp++)
{
if (*dcehp)
{
if (busyOnly && (**dcehp)->dCtlQHdr.qHead == 0)
continue;
DCEsUsed++;
if (!foundOne)
{
DrawHdr();
foundOne = true;
}
DrawDCE(~dnum,**dcehp);
}
if (paramPtr->aborted)
break;
}
if ( !paramPtr->aborted )
{
if ( busyOnly )
{
if ( !foundOne )
{
PutPStr("\pNo drivers are busy.");
PutLine();
}
}
else
{
PutUDec(NumDCEs);
PutPStr("\p Unit Table entries, ");
PutUDec(DCEsUsed);
PutPStr("\p in use, ");
PutUDec(NumDCEs - DCEsUsed);
PutPStr("\p free");
PutLine();
}
}
}
dcmdSwapWorlds();
} // DoDrvrCommand
pascal void CommandEntry(dcmdBlock* paramPtr)
{
static const Str255 usageStr = "\p[refNum|num] | -b";
switch (paramPtr->request)
{
case dcmdInit:
break;
case dcmdHelp:
dcmdDrawLine("\pDisplays driver information for the given refNum or all installed");
dcmdDrawLine("\pdrivers. Flags are B/b=Busy, H/P=Handle/Ptr, O/C=Open/Closed.");
dcmdDrawLine("\p drvr -b shows only the drivers that are busy.");
break;
case dcmdGetInfo:
* (long *) &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->dcmdVersion = 0x03018000; // version 3.0.1 final
BlockMoveData(&usageStr, &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->usageStr, usageStr[0]+1);
break;
case dcmdDoIt:
DoDrvrCommand(paramPtr);
break;
// Version 3 and newer dcmds must quietly ignore requests we don't recognize.
default:
break;
}
} // CommandEntry